package com.sso.managedBean;

import javax.faces.context.FacesContext;

import org.operamasks.faces.annotation.Accessible;
import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.BeforeRender;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.Inject;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.annotation.SaveState;
import org.operamasks.faces.user.util.Browser;

import com.base.commons.SpringBeanHolder;
import com.base.utils.IdUtils;
import com.sso.entity.DicSystem;
import com.sso.entity.DicSystemUser;
import com.sso.service.IDicSystemService;
import com.sso.service.IDicSystemUserService;
@ManagedBean(name = "sso_addUserBean", scope = ManagedBeanScope.REQUEST)
public class AddUserBean {
	protected IDicSystemUserService dicSystemUserService = SpringBeanHolder
	.getBean("dicSystemUserService");
	
	@Bind
	@Accessible
	@SaveState
	String id;
	@Bind
	@Accessible
	@SaveState
	protected String userID;
	protected DicSystemUser user;
	// 系统用户名称
	@Bind(id = "userName", attribute = "value")
	protected String userName;
	// 密码
	@Bind(id = "userPassword", attribute = "value")
	protected String userPassword;
	
	@Inject
	private FacesContext context;

	@SaveState
	private String first;
	
	@BeforeRender
	public void beforeRender(boolean isPostback) {
		if (!isPostback) {
			id = IdUtils.getUUID();
		}
	}
	
	@Action(id = "save")
	public void save() {
		user = new DicSystemUser();
		user.setId(id);
		user.setUserName(userName);
		user.setUserPassword(userPassword);
		dicSystemUserService.saveDicSystemUser(user);
		Browser
				.execClientScript("javascript:closeCenterLayoutTab('addUserTab')");
	}
}
